package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.DaKaXiqngQingBean;
import com.oscar.ehome.bean.pagebean.HuokeBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.util.DateUtil;
import com.oscar.ehome.view.pageview.TeamCountNewActivity;
import com.oscar.ehome.view.teamview.TeamDetailActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/11/23
 */

public class DaKaXqAdapter extends BaseAdapter {

    private List<DaKaXiqngQingBean.ss> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    DaKaXiqngQingBean.ss bean;


    public DaKaXqAdapter(Context context, List<DaKaXiqngQingBean.ss> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<DaKaXiqngQingBean.ss> list) {
        this.list = list;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        DaKaXqAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.dakaxqitem, null);
            holder = new DaKaXqAdapter.ViewHolder();
            holder.daka_name = (TextView) convertView.findViewById(R.id.daka_name);
            holder.daka_imghead = (ImageView) convertView.findViewById(R.id.daka_imghead);
            holder.daka_level = (TextView) convertView.findViewById(R.id.daka_level);
            holder.dakashijian = (TextView) convertView.findViewById(R.id.dakashijian);

            convertView.setTag(holder);
        } else {
            holder = (DaKaXqAdapter.ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            bean = list.get(position);
            if (bean != null) {


                    GildeUtils.loadUrlImages(C.qiniu_ip + bean.getCreateBy().getPhoto() , holder.daka_imghead, mContext);

                if (bean.getCreateBy().getName() != null && !"".equals(bean.getCreateBy().getName() )) {
//
                    holder.daka_name.setText(bean.getCreateBy().getName());
                }
                if (bean.getCreateBy().getRoleMobile().getRoleName() != null && !bean.getCreateBy().getRoleMobile().getRoleName().equals("")) {
                    holder.daka_level.setText(bean.getCreateBy().getRoleMobile().getRoleName());
                }
                if (bean.getCreateDate() != null && !bean.getCreateDate() .equals("")) {
                    String ss=bean.getCreateDate().substring(11);

                    holder.dakashijian.setText(ss);
                }
            }
            holder.daka_imghead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent intent = new Intent(mContext, TeamDetailActivity.class);
                    intent.putExtra("id", list.get(position).getCreateBy().getId());
                    intent.putExtra("set", 2);
                    mContext.startActivity(intent);
                }
            });
        }

        return convertView;
    }

    class ViewHolder {
        TextView daka_level;//
        TextView daka_name;//
        TextView dakashijian;//
        ImageView daka_imghead;
    }

}
